package com.ssm.design.chain;

import com.ssm.design.chain.context.OrderHandleContextV3;
import com.ssm.design.chain.handler.v3.AbstractOrderHandlerV3;
import com.ssm.design.chain.handler.v4.OrderHandlerV4;
import com.ssm.design.common.enums.OrderTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class OrderHandlerChainV4 {

    @Autowired
    private List<OrderHandlerV4> chain;
    @Autowired
    private ApplicationContext applicationContext;

    public void handle(OrderHandleContextV3 context,
                       Object... objects) {
        log.info("AbstractOrderHandlerV3 Beans: {}",
                applicationContext.getBeanNamesForType(OrderHandlerV4.class));
        if (context.getPos() < chain.size()) {
            OrderHandlerV4 handler = chain.get(context.getPos());
            // 移动位于处理器链中的位置
            context.setPos(context.getPos() + 1);
            handler.handle(context, this, objects);
        }
    }


}